<?php

namespace app\index\controller;

//use app\index\controller\BaseController;


class Location extends BaseController
{
    public function index($api)
    {

       $data= $this->curl($api);
        $message=[
            'formatted_address'=>$data['result']['formatted_address'],
            'province'=>$data['result']['addressComponent']['province'],
            'city'=>$data['result']['addressComponent']['city'],
            'district'=>$data['result']['addressComponent']['district'],
        ];
        return json_encode($message);

    }

    /**
     * 百度地图算路
     * @param $originLat    起始纬度
     * @param $originLng    起始经度
     * @param $destinationsLat  起始纬度
     * @param $destinationsLng  起始经度
     */
    public function computeDistance($originLat,$originLng,$destinationsLat,$destinationsLng)
    {

        $url="http://api.map.baidu.com/routematrix/v2/driving?output=json&origins={$originLat},{$originLng}&destinations={$destinationsLat},{$destinationsLng}&ak=EDOWlqG8r4R2zxnAyRiwOony40pojGGe&tactics=11";

        $data=$this->curl($url);

        return $data['result'][0]['distance'];  //数组后缀text为公里,value为米

    }


}